/**
 * 
 */
package main;

import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;

import tools.DoubleVector;
import tools.Vector;
import uncertainty.BertSimasUncertSet;
import uncertainty.UncertaintySet;


public class MainFunctions {
	
	public static Vector<Double> readDemandCosts(BufferedReader data) throws IOException {
		int dim = Integer.parseInt(data.readLine());
		Vector<Double> d = new DoubleVector(dim);
		for(int i = 0; i < dim; i++) d.set(i, Double.parseDouble(data.readLine()));
		return d;
	}
	
	public static Vector<Double> readStorageCosts(BufferedReader data) throws IOException {
		int dim = Integer.parseInt(data.readLine());
		Vector<Double> d = new DoubleVector(dim);
		for(int i = 0; i < dim; i++) d.set(i, Double.parseDouble(data.readLine()));
		return d;	
	}
	
	public static Vector<Double> readShortageCosts(BufferedReader data) throws IOException {
		int dim = Integer.parseInt(data.readLine());
		Vector<Double> d = new DoubleVector(dim);
		for(int i = 0; i < dim; i++) d.set(i, Double.parseDouble(data.readLine()));
		return d;
	}
	
	public static Vector<Double> readBounds(BufferedReader data) throws IOException {
		int dim = Integer.parseInt(data.readLine());
		Vector<Double> d = new DoubleVector(dim);
		for(int i = 0; i < dim; i++) d.set(i, Double.parseDouble(data.readLine()));
		return d;
	}
	
	public static UncertaintySet readUncertainSet(int gamma, BufferedReader data) throws IOException {
		UncertaintySet s;
		Vector<Double> md;
		Vector<Double> vd;
		int dim = Integer.parseInt(data.readLine());
		md = new DoubleVector(dim);
		vd = new DoubleVector(dim);
		
		for(int i = 0; i < dim; i++)md.set(i, Double.parseDouble(data.readLine()));

		data.readLine();
		for(int i = 0; i < dim; i++)vd.set(i, Double.parseDouble(data.readLine()));	
		
		s= new BertSimasUncertSet(dim, gamma, md, vd);
		
		return s;
	}
	
	public static void writeSol(FileWriter file, String set, int dim, int k,  int gamma, int numvert, String name, double value, double time) throws IOException{
		file.append(name + "\n" + Integer.toString(dim) + "\n" + set  + "\n" + Integer.toString(k) + "\n" + Integer.toString(gamma) + "\n" + Integer.toString(numvert) + "\n" + Double.toString(value) + "\n" + Double.toString(time)+"\n");
	}

	public static void writeBound(FileWriter file, int dim, int gamma, String name, double b1, double b2) throws IOException {
		file.append(name + "\n" + Integer.toString(dim)   + "\n" + Integer.toString(gamma) + "\n" + Double.toString(b1) + "\n" + Double.toString(b2)+"\n");
	}

}
